<template>
	<scroll-view class="content-style" scroll-y lower-threshold="50" @scrolltolower="scrolltolower">
		<view class="header-top"></view>
		<view class="media-list">
			<block v-for="(item, index) in list" :key="index">
				<view class="media-box" @click="detail(item)">
					<image class="image" :src="item.mainImageUrl" mode="aspectFill"></image>
					<view class="right-box">
						<text class="title">{{item.title}}</text>
						<view class="bottom">
							<view class="row-center">
								<view class="tag">{{item.informationTypeNameCN}}</view>
								<view class="row-center">
									<image class="hits-icon" src="@/static/image/ckrs.png"></image>
									<text class="hits">{{item.view}}</text>
								</view>
							</view>
							<view class="inputtime">{{item.releaseTime}}</view>
						</view>
					</view>
				</view>
			</block>
		</view>
	</scroll-view>
</template>

<script>
	import { list } from '@/api/media/index'
	export default {
		data() {
			return {
				page: 1,
				total: 0,
				list: []
			}
		},
		onLoad() {
			this.loadData();
		},
		methods: {
			loadData() {
				list({page: this.page, limit: 10, id:""}, (response, total) => {
					this.total = total;
					if (this.page == 1) {
						this.list = response;
					}else {
						this.list = this.list.concat(response);
					}
				})
			},
			
			detail(item) {
				item.view = item.view + 1;
				uni.navigateTo({
					url: `detail?id=${item.id}`
				})
			},
			
			scrolltolower() {
				if (this.total > this.list.length) {
					this.page++
					this.loadData()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>	
	.media-list {
		position: absolute;
		display: flex;
		flex-direction: column;
		width: 100vw;
		padding-bottom: 30rpx;
		
		.media-box {
			display: flex;
			margin: 30rpx 30rpx 0;
			padding: 30rpx 25rpx;
			background-color: #fff;
			border-radius: 20rpx;
			border: 1rpx solid #ebecfe;
			.image {
				width: 210rpx;
				height: 164rpx;
			}
			.right-box {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				flex: 1;
				margin-left: 20rpx;
				.title {
					font-size: 28rpx;
					color: #101010;
					font-weight: bold;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					white-space: normal;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}
				
				.bottom {
					display: flex;
					align-items: center;
					justify-content: space-between;
					.tag {
						height: 32rpx;
						background-color: rgba(27, 140, 239, 0.11);
						font-size: 22rpx;
						line-height: 32rpx;
						color: #1B77EF;
						padding: 0 15rpx;
						margin-right: 20rpx;
					}
					.hits-icon {
						width: 24rpx;
						height: 19rpx;
					}
					.hits {
						font-size: 22rpx;
						color: #999999;
						margin-left: 5rpx;
					}
					.inputtime {
						font-size: 22rpx;
						color: #999999;
					}
				}
			}
		}
	}
</style>